package fr.mmt.gisfizz.handler;

import fr.mmt.gisfizz.entity.AbstractEntity;
import java.io.IOException;
import java.io.Serializable;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import org.springframework.data.domain.Page;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestParam;

public interface CrudHandler<E extends AbstractEntity, PK extends Serializable> {

    /**
     * Get.
     *
     * @param request
     * @param response
     * @param id
     * @return
     */
    E get(final HttpServletRequest request, final HttpServletResponse response, @PathVariable PK id);

    /**
     * Search.
     *
     * @param request
     * @param response
     * @param search
     * @param page
     * @param size
     * @param sortColumn
     * @param sortDirection
     * @return
     */
    Page<E> search(final HttpServletRequest request, final HttpServletResponse response, @RequestParam(required = false) String search, @RequestParam(required = false) Integer page, @RequestParam(required = false) Integer size, @RequestParam(required = false) String sortColumn, @RequestParam(required = false) String sortDirection);

    /**
     * Create.
     *
     * @param request
     * @param response
     * @param newObj
     * @return Object created
     */
    E create(final HttpServletRequest request, final HttpServletResponse response, @RequestBody E newObj);

    /**
     * Delete.
     *
     * @param request
     * @param response
     * @param id
     */
    void delete(final HttpServletRequest request, final HttpServletResponse response, @PathVariable PK id);

    /**
     * Update.
     *
     * @param request
     * @param response
     * @param updObj
     * @param id
     * @return
     */
    E update(final HttpServletRequest request, final HttpServletResponse response, @RequestBody E updObj, @PathVariable PK id);
}
